/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin			*/
/*	Project:	GlbCloud			*/
/*	Author:		gong_libin			*/
/*	Date:		2012_01_06			*/
/*	File:		MrConf.h			*/
/********************************************************/

#ifndef	_MRCONF_H
#define	_MRCONF_H

#include "MrGlobal.h"

#define	MR_ERR_OEN			1
#define	MR_ERR_SEC			2
#define	MR_ERR_KEY			3
#define	MR_ERR_VAL			4
#define	MR_ERR_CLS			5
#define	MR_ERR_OTH			6

#define	MR_CTRL_T			'\t'
#define	MR_CTRL_R			'\r'
#define	MR_CTRL_N			'\n'

#define	MR_SEC_L			'['
#define	MR_SEC_R			']'

#define	MR_BLANK			' '
#define	MR_EQUAL			'='
#define	MR_RMRARK			'#'

class CMrConf
{
public:
	CMrConf();
	virtual ~CMrConf();

	void MrConfClose();
	int MrConfOpen(char* pszFile);
	int MrConfGetSec(char* pszSec);
	void MrConfTrim(char* pszLine);
	bool MrConfIsValid(char* pszLine);
	bool MrConfIsSection(char* pszLine);
	int MrConfGetLine(char* pszLine, int iSize);
	int MrConfGetKey(char* pszSec, char* pszKey);
	int MrConfGetVal(char* pszSec, char* pszKey, char* pszVal);
	int MrConfKeyValue(char* pszLine, char* pszKey, char* pszVal);
	int MrConfKeyValue(char* pszLine, char** ppszKey, char** ppszVal);

private:
	FILE* m_pstFile;

	void MrConfTrimLeft(char* pszLine);
	void MrConfTrimRight(char* pszLine);

};

typedef struct tagMrConfig
{
	char m_szID[MR_BUFFER];
	char m_szHost[MR_BUFFER];
	char m_szPort[MR_BUFFER];
	char m_szDbase[MR_BUFFER];
	char m_szTable[MR_BUFFER];
}MRCONFIG_S;

int MrConfig(char* pszFile, MRCONFIG_S* pstConf);

#endif /* _MRCONF_H */
